package com.magirard.project.shader 
{
	import com.adobe.utils.AGALMiniAssembler;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Program3D;
	
	public class BaseShader implements IBaseShader
	{		
		protected var mVertexShaderAGAL:String;
		protected var mFragmentShaderAGAL:String;
			
		protected var mProgram:Program3D;
		protected var mContext3d:Context3D;
		
		protected var mVertexAssembler:AGALMiniAssembler = new AGALMiniAssembler();
		protected var mFragmentAssembler:AGALMiniAssembler = new AGALMiniAssembler();
		
		public function BaseShader()
		{
			
		}
		
		public function Init(aContext:Context3D):void
		{
			mContext3d = aContext;
			mProgram = mContext3d.createProgram();
		}
		
		public function Compile():void
		{
			mVertexAssembler.assemble(Context3DProgramType.VERTEX, mVertexShaderAGAL);
			mFragmentAssembler.assemble(Context3DProgramType.FRAGMENT, mFragmentShaderAGAL);
			mProgram.upload(mVertexAssembler.agalcode, mFragmentAssembler.agalcode);
		}
		
		public function get FragmentShader():String 
		{
			return mFragmentShaderAGAL;
		}
		
		public function set FragmentShader(value:String):void 
		{
			mFragmentShaderAGAL = value;
		}
		
		public function get VertexShader():String 
		{
			return mVertexShaderAGAL;
		}
		
		public function set VertexShader(value:String):void 
		{
			mVertexShaderAGAL = value;
		}
		
		public function get Program():Program3D 
		{
			return mProgram;
		}
		
		public function set Program(value:Program3D):void 
		{
			mProgram = value;
		}
		
	}

}